<?php
    require_once('../code/global.php');
    require_once('/code/Admin.php');
    require_once('/code/News.php');
    $admin=new Admin();
    $admin->loginCheck(1);
    if(!isset($_GET['nid'])) {header('Location:news.html');exit;}
    $nid=intval($_GET['nid']);
    $news=new News();
    $n=$news->getNewsById($nid);
    if(empty($n)) {header('Location:news.html');exit;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>PhotoFromThe1st 后台管理系统</title>
        <link rel="stylesheet" href="/styles/admin.css" type="text/css" media="all">
        <script type="text/javascript" src="/script/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="/script/script.js"></script>
        <script type="text/javascript">
            window.parent.scroll(0,0);
        </script>
    </head>
    <body>
        <?php
            echo '<div class="msgBox">'.(isset($_GET['msg'])?$_GET['msg']:'编辑新闻').' <a href="news.html">返回</a></div>';
        ?>
        <table border="0" cellspacing="0" cellpadding="0" class="detailTable">
                <?php if(!empty($n['img_url'])) echo '<tr><td class="align-center"><form name="deleteNewsImg" action="../code/exec.php" method="post"><input type="hidden" name="action" value="deleteNewsImg"><input type="hidden" name="news_id" value="'.$nid.'"><input class="btnLnk btnDel" type="submit" name="delete" value="Delete Image"></form></td><td><img src="'.$n['img_url'].'?'.rand().'"/></td></tr>' ?>
                <tr class="seperator"><td colspan="2"></td></tr>
            <form name="uploadNewsImg" action="../code/exec.php" method="post" enctype="multipart/form-data">
                <input type="hidden" name="action" value="uploadNewsImg"><input type="hidden" name="max_file_size" value="10000000"><input type="hidden" name="news_id" value="<?php echo $nid; ?>">
                <tr><td>Upload Image:<br />(replaces old)</td><td><input type="file" name="imgFile"><input class="btnLnk" type="submit" id="btnUpload" value="Upload News Image" onclick="wait()"></td></tr>
            </form>
            <form name="editNews" action="../code/exec.php" method="post">
                <input type="hidden" name="action" value="editNews">
                <input type="hidden" name="news_id" value="<?php echo $nid; ?>">
                <tr><td>Caption:</td><td><input type="text" name="caption" maxlength="128" class="inputBox" value="<?php echo $n['caption']; ?>"></td></tr>
                <tr><td>Abstract:</td><td><textarea id="abstract" name="abstract" rows="2" maxlength="128"><?php echo $n['abstract']; ?></textarea></td></tr>
                <tr><td>Content:</td><td><textarea id="content" name="content"><?php echo $n['content']; ?></textarea></td></tr>
                <tr><td>Active:</td><td><input name="is_active" type="checkbox"<?php echo $n['is_active']? 'checked':''; ?>></td></tr>
                <tr><td>Created:</td><td><?php echo $n['create_time']?></td></tr>
                <tr><td>Modified:</td><td><?php echo $n['modify_time']?></td></tr>
                <tr class="btnTr header"><td colspan="2"><input class="btnLnk" type="submit" name="save" value="Save"><input class="btnLnk" type="reset" name="reset" value="Reset"><input  class="btnLnk" type="button" name="cancel" value="Cancel" onclick="location.href='news.html'"></td></tr>
            </form>
            <form name="deleteNews" action="../code/exec.php" method="post"><input type="hidden" name="action" value="deleteNews"><input type="hidden" name="news_id" value="<?php echo $nid; ?>">
                <tr class="btnTr header"><td colspan="2"><input class="btnLnk btnDel" type="submit" name="delete" value="Delete"></td></tr>
            </form>
        </table>
    </body>
</html>